<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <style>
      .imgdiv {
        width: 224px;
        height: 160px;
        border: 1px #ccc solid;
        display: inline-block;
        margin: 10px auto;
        margin-right: 100px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      
      <div>我裸奔</div>
      <m-test v-if="show" :no="1"></m-test>

      <div>我有保护层</div>
      <keep-alive> <m-test v-if="show" :no="2"></m-test> </keep-alive>

      <button @click="toggleShow">切换</button>
    </div>

    <script>
      Vue.component("m-test", {
        template: "<div>{{times}}</div>",
        props: ["no"],
        data: function() {
          return {
            times: 0
          };
        },
        created: function() {
          this.times = new Date().getTime();
        },
        activated: function() {
          console.log(this.no + ":activated");
        }
      });

      // 创建根实例
      new Vue({
        el: "#app",
        data: {
          show: true
        },
        methods: {
          toggleShow: function() {
            this.show = !this.show;
          }
        }
      });
    </script>
  </body>
</html>
